package com.rqbl.service.impl;

import com.rqbl.entity.User;
import com.rqbl.mapper.FriendMapper;
import com.rqbl.myutils.PageBean;
import com.rqbl.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bruce
 * @since 2024-07-19
 */
@Service
public class FriendServiceImpl implements FriendService {

    @Autowired
    private FriendMapper friendMapper;

    @Override
    public List<User> getFriendByUid(PageBean pageBean, User user) {
        pageBean.setTotalSize(friendMapper.selectAllFriendCountByUid());
        int totalPage = pageBean.getTotalSize() / pageBean.getPageSize();
        if(pageBean.getTotalSize() % pageBean.getPageSize() != 0) {
            totalPage++;
        }
        pageBean.setTotalPage(totalPage);
        return friendMapper.getFriendByUid((pageBean.getPage()-1)*pageBean.getPageSize(), pageBean.getPageSize(), user.getUid());
    }

    @Override
    public void deleteFriendByUid(Integer uid1, Integer uid2) {
        friendMapper.deleteFriendByUid(uid1, uid2);
    }
}
